

import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
class DioDemo extends StatefulWidget {
  const DioDemo({Key? key}) : super(key: key);

  @override
  State<DioDemo> createState() => _DioDemoState();
}

class _DioDemoState extends State<DioDemo> {
    List _list = [];
    @override
  void initState() {
    super.initState();
    this._getData();
  }

  _getData() async{
    var response = await Dio().get('https://jdmall.itying.com/api/plist');
    print(response.data);
    print(response.statusCode);
    if(response.statusCode == 200){
      setState(() {
        this._list = response.data["result"];
      });
    }else{
      print(response.statusCode);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("请求数据Demo-Dio"),
      ),
      body: this._list.length>0?ListView(
        children: this._list.map((e){
          return ListTile(title: Text(e["title"]),);
        }).toList(),
      ):Text(" "),
    );
    
  }
}